package cn.maihe.elg.operation.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @Description
 * @Author WJH
 * @Date 2021/04/26
 */
@Configuration
@ConfigurationProperties(prefix = "cn.maihe.elg.resource")
@Data
public class ElgResourceConfig {
    /**
     * elg资源的根目录
     */
    private String basePath;
    /**
     * 相对根目录的保函相关文件目录;/ofd/acceptOrderNO/**.*
     */
    private String ofdPath;
    /**
     * excel模板相对路径
     */
    private String excelTemplate;


    public Path getAbsolutePath(String relativePath) {
        return Paths.get(this.basePath, relativePath);
    }

    public String getRelativePath(Path absolutePath) {
        String relativePath = absolutePath.toString().replaceFirst(Paths.get(getBasePath()).toString().replace("\\","\\\\"), "");
        return relativePath.replace("\\","/");
    }
    //获得相对路径
    public String getPath(Path absolutePath) {
        Path basePath = Paths.get(getBasePath());
        Path relativePath = basePath.relativize(absolutePath);
        return relativePath.toString().replace('\\', '/');
    }

}
